<?php
	//后台登陆验证文件
	session_start();
	
	
	require_once('../include/config.inc.php');
	require_once(INCLUDE_PATH.'admin.inc.php');
	
	$admin = new Admin();
	
	
	//判断是否是提交请求，若是则添加数据
	if($_SERVER['REQUEST_METHOD'] == 'POST'){				   
		
		$picValidate = $_POST['picValidate'];
		if($picValidate!=$_SESSION['picValidate']){
			
			$errmsg = "验证码错误，请重新输入！";
			$url = "login.php?$msg=$errmsg";
			echo "<script language='javascript' type='text/javascript'>";
			echo "window.location.href='$url'";
			echo "</script>";
			return false;
			
		}
		$name = $_POST['name'];
		$password = $_POST['password'];
		
		
		$check_query = $admin->getAdminByNameAndPassword($name, $password, $admin->_tbName);
		if($check_query){

			$_SESSION['adminName'] = $name;
			$_SESSION['adminid'] = $check_query['adminId'];
			echo "登录成功，转向后台页面....";
			$url = "main.html";
			echo "<script language='javascript' type='text/javascript'>";
			echo "window.location.href='$url'";
			echo "</script>";
			
		}else{
			echo "<script language='javascript' type='text/javascript'>";
			echo "alert('用户名或密码错误，请重新输入！')";
			echo "window.location.href='$url'";
			echo "</script>";
		}
		
	}

?>